/**
 * @param {number[][]} brackets
 * @param {number} income
 * @return {number}
 */
var calculateTax = function(brackets, income) {
  let result = 0;
  for(let i = 0; i < brackets.length; i++) {
    if(income > brackets[i][0]) {
      if(i == 0) {
        result += brackets[i][0] * (brackets[i][1] / 100);
      } else {
        result += (brackets[i][0] - brackets[i - 1][0]) * (brackets[i][1] / 100);
      }
    } else {
      if(i == 0) {
        result += (income) * (brackets[i][1] / 100);
      } else {
        result += (income - brackets[i - 1][0]) * (brackets[i][1] / 100);
      }
      break;
    }
  }
  return result;
};
let brackets = [[3,50],[7,10],[12,25]], income = 10;
console.log(calculateTax(brackets, income));
brackets = [[1,0],[4,25],[5,50]], income = 2;
console.log(calculateTax(brackets, income));
brackets = [[2,50]], income = 0;
console.log(calculateTax(brackets, income));
